package entity_controllers.fieldcontrollers;

import misc.MArrayList;
import core.subcontrollers.SubController;
import ie.FieldBoard;
import ie.PlayerBoard;
import ie.Shaker;
import dto.Field;
import dto.Player;
import dto.PropertyField;
import entity.fields.properties.Street;

public class StreetController extends PropertyController {

	private int numberOfSameColor;

	@Override
	public void execute(Player player, Field field, FieldBoard fieldBoard, PlayerBoard playerBoard, Shaker shaker) {
		MArrayList<Street> streets = new MArrayList<Street>();
		for (int i = 0; i < fieldBoard.getFields().length; i++) {
			if (fieldBoard.getFields()[i].getClass().equals(Street.class))
				streets.add((Street) fieldBoard.getFields()[i]);
		}
		numberOfSameColor = SubController.getNumberOfStreetsWithSameColor((Street) field, streets.getArray());

		super.execute(player, field, fieldBoard, playerBoard, shaker);
	}

	@Override
	public int getRent(PropertyField property) {

		int ownedStreets = property.getOwner().getAccount().getNumberOfFields(Street.class);

		if (numberOfSameColor > 0 && numberOfSameColor == ownedStreets && ((Street) property).getBuildings() == 0)
			return property.getRent() * 2;
		else
			return property.getRent();

	}

}
